(function (vc, vm) {
    vc.extends({
        data: {
            editHousekeepingFeeConfigInfo: {
                configId: '',
                feeName: '',
                feeTypeCd: '',
                computingFormula: '',
                computingFormulas: [],
                feePrice: '',
                startTime: '',
                endTime: '',
                isDefault: '',
                isDefaults: [],
                housekeepingFeeTypes: []
            }
        },
        _initMethod: function () {
            //$that._listEditHousekeepingFeeTypes();
            vc.initDate('editStartTime', function (_value) {
                $that.editHousekeepingFeeConfigInfo.startTime = _value;
            });
            vc.initDate('editEndTime', function (_value) {
                $that.editHousekeepingFeeConfigInfo.endTime = _value;
            });
        },
        _initEvent: function () {
            vc.on('editHousekeepingFeeConfig', 'openEditHousekeepingFeeConfigModal', function (_params) {
                $that.refreshEditHousekeepingFeeConfigInfo();
                vc.getDict('housekeeping_fee_config', "is_default", function (_data) {
                    $that.editHousekeepingFeeConfigInfo.isDefaults = _data;
                });
                vc.getDict('housekeeping_fee_config', "computing_formula", function (_data) {
                    $that.editHousekeepingFeeConfigInfo.computingFormulas = _data;
                });
                $('#editHousekeepingFeeConfigModel').modal('show');
                vc.copyObject(_params, $that.editHousekeepingFeeConfigInfo);
            });
        },
        methods: {
            editHousekeepingFeeConfigValidate: function () {
                return vc.validate.validate({
                    editHousekeepingFeeConfigInfo: $that.editHousekeepingFeeConfigInfo
                }, {
                    'editHousekeepingFeeConfigInfo.feeName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "费用名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "128",
                            errInfo: "费用名称太长"
                        }
                    ],
                    'editHousekeepingFeeConfigInfo.feeTypeCd': [
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "费用类型太长"
                        },
                    ],
                    'editHousekeepingFeeConfigInfo.computingFormula': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "计算公式不能为空"
                        }
                    ],
                    'editHousekeepingFeeConfigInfo.startTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "开始时间不能为空"
                        }
                    ],
                    'editHousekeepingFeeConfigInfo.endTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "结束时间不能为空"
                        }
                    ],
                    'editHousekeepingFeeConfigInfo.isDefault': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "是否未默认费用不能为空"
                        }
                    ],
                    'editHousekeepingFeeConfigInfo.configId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "标准ID不能为空"
                        }
                    ]
                });
            },
            editHousekeepingFeeConfig: function () {
                if (!$that.editHousekeepingFeeConfigValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                if ($that.editHousekeepingFeeConfigInfo.computingFormula == '2002' && $that.editHousekeepingFeeConfigInfo.feePrice == "") {
                    vc.toast("请填写单价");
                    return;
                }
                $that.editHousekeepingFeeConfigInfo.shopId = vc.getCurrentCommunity().shopId;
                vc.http.apiPost(
                    '/housekeepingFeeConfig/updateHousekeepingFeeConfig',
                    JSON.stringify($that.editHousekeepingFeeConfigInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editHousekeepingFeeConfigModel').modal('hide');
                            vc.emit('housekeepingFeeConfigManage', 'listHousekeepingFeeConfig', {});
                            vc.toast("修改成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            //查询方法
            _listEditHousekeepingFeeTypes: function (_page, _rows) {
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/housekeepingFeeType/queryHousekeepingFeeType',
                    param,
                    function (json, res) {
                        var _housekeepingFeeTypeManageInfo = JSON.parse(json);
                        $that.editHousekeepingFeeConfigInfo.housekeepingFeeTypes = _housekeepingFeeTypeManageInfo.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            refreshEditHousekeepingFeeConfigInfo: function () {
                let _housekeepingFeeTypes = $that.editHousekeepingFeeConfigInfo.housekeepingFeeTypes;
                $that.editHousekeepingFeeConfigInfo = {
                    configId: '',
                    feeName: '',
                    feeTypeCd: '',
                    computingFormula: '',
                    computingFormulas: [],
                    feePrice: '',
                    startTime: '',
                    endTime: '',
                    isDefault: '',
                    isDefaults: [],
                    housekeepingFeeTypes: _housekeepingFeeTypes
                }
            }
        }
    });
})(window.vc, window.$that);
